import java.io.*;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;

/**
 * Created by zyl on 17-6-2.
 */
public class SDec {
    public static String Dec(String s) throws Exception{

        int i;
        byte[] ctext;
        /*

        // 获取密文

        FileInputStream f=new FileInputStream("SEnc.dat");

        int num=f.available();

        byte[ ] ctext=new byte[num];

        f.read(ctext);

        */

        ctext = s.getBytes();

        // 获取密钥

        FileInputStream  f2=new FileInputStream("keykb1.dat");
        int num2=f2.available();
        byte[ ] keykb=new byte[num2];
        f2.read(keykb);

        // 解密

        SecretKeySpec k=new  SecretKeySpec(keykb,"DESede");
        Cipher cp=Cipher.getInstance("DESede");
        cp.init(Cipher.DECRYPT_MODE, k);
        byte []ptext=cp.doFinal(ctext);
        // 显示明文

        String p=new String(ptext,"UTF8");
        //System.out.println(p);

        return p;
    }

}
